#version 450

in vec3 varNormal;
in vec2 varUv;
layout(binding=0) uniform sampler2D TilingMap;
layout(binding=1) uniform sampler2D LowFreqMap;
layout(binding=2) uniform sampler2D HighFreqMap;

layout(location=10) uniform unsigned int mode;
layout(location=11) uniform float tiling;

void main(void)
{
	vec4 color;
	vec2 uv = varUv*4;
	if(0==mode)//tiling mode
	{
		color = texture(TilingMap, uv*tiling);
	}
	else if(1==mode) // detail mapping
	{
		color = texture(LowFreqMap, uv) + (texture(HighFreqMap, uv*tiling)*2 - 1);
	}
	else
		color = vec4(1, mode, 0, 1);
	
	
	// lighting
	vec3 normal = normalize(varNormal);
	vec3 lightDir = normalize(vec3(1, 1, 1));
	float light = max(0, dot(normal, lightDir)) * 0.8;
	
	gl_FragColor = color * (0.2+light);
}
